package cn.group.service.impl;

import cn.group.dao.TeachInfoDao;
import cn.group.domain.TeachInfo;
import cn.group.domain.Teacher;
import cn.group.service.TeachInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeachInfoServiceImpl implements TeachInfoService {
    private TeachInfoDao teachInfoDao;
    @Autowired
    public TeachInfoServiceImpl(TeachInfoDao teachInfoDao){this.teachInfoDao = teachInfoDao;}
//查询所有
    @Override
    public List<TeachInfo> getAll() {
        return teachInfoDao.queryAll();
    }
//分页
    @Override
    public PageInfo<TeachInfo> getTeachInfoByPage(Integer currentPage, Integer pagesize) {
        //pagehelper内部计算总共有多少页
        PageHelper.startPage(currentPage,pagesize);
        List<TeachInfo>teachInfoList = teachInfoDao.queryAll();
        PageInfo<TeachInfo>pageInfo = new PageInfo<>(teachInfoList);
        return pageInfo;
    }

    @Override
    public TeachInfo getOneById(Integer id) {
        TeachInfo teachInfo = teachInfoDao.queryById(id);
        return teachInfo;
    }

    @Override
    public boolean modifyOne(TeachInfo teachInfo) {
        int result = teachInfoDao.updateByTeachInfo(teachInfo);
        return result>0;
    }

    @Override
    public boolean addOne(TeachInfo teachInfo) {
        int result = teachInfoDao.insertByTeachInfo(teachInfo);
        return result>0;
    }
}
